class UserController < ApplicationController

  def index
    
  end
    

  def create
    @user = User.new(params[:user])
    @address = @user.address = Address.new(params[:address])
           
    if @user.save      
      flash[:notice] = 'User successfully created'
      APPLOG.info 'User # ' + @user.id.to_s + ' was successfully inserted!'
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end


  def update
    @user = User.get_by_id(params[:id])
    @address = @user.address
    
    if @user.update_attributes(params[:user]) && @address.update_attributes(params[:address])
      flash[:notice] = 'User successfully updated.'
      APPLOG.info 'User # ' + @user.id + ' was successfully updated!'  
      redirect_to :action => 'show', :id => @user
    else
      APPLOG.info 'Could not update!'
      render :action => 'edit'
    end
  end


  def delete
    User.delete(params[:id])
  end


  def show
    @user = User.get_by_id(params[:id])
  end


  def list
    @page_title = 'List all system users'
    @users = User.get_all
  end

  
  def new
    @user = User.new
    @address = Address.new
    @role = Role.new
  end
  
  
  def edit
    @user = User.get_by_id(params[:id])
    @address = @user.address
  end
end
